﻿namespace Sidvall.Data
{
    public static class CriteriaManager
    {
        #region NewCommandCriteria

        public static CommandCriteria NewCommandCriteria(string criteriaId)
        {
            return new CommandCriteria()
            {
                CriteriaId = criteriaId
            };
        }

        public static CommandCriteria NewCommandCriteria(string criteriaId, ParameterCollection parameters)
        {
            return new CommandCriteria()
            {
                CriteriaId = criteriaId,
                Parameters = parameters
            };
        }

        #endregion
        #region NewCreateCriteria

        public static CreateCriteria NewCreateCriteria()
        {
            return new CreateCriteria();
        }
        public static CreateCriteria NewCreateCriteria(string criteriaId, ParameterCollection parameters)
        {
            return new CreateCriteria()
            {
                CriteriaId = criteriaId,
                Parameters = parameters,
            };
        }

        #endregion
        #region NewDeleteCriteria

        public static DeleteCriteria<TField> NewDeleteCriteria<TField>()
        {
            return new DeleteCriteria<TField>();
        }
        public static DeleteCriteria<TField> NewDeleteCriteria<TField>(string criteriaId, ParameterCollection parameters)
        {
            return new DeleteCriteria<TField>()
            {
                CriteriaId = criteriaId,
                Parameters = parameters,
            };
        }
        public static DeleteCriteria<TField> NewDeleteCriteria<TField>(Filter<TField> filterItems, SortItemCollection<TField> sortItems, int? rowStartIndex, int? rowCount)
        {
            return new DeleteCriteria<TField>()
            {
                Filter = filterItems,
                RowCount = rowCount,
                RowStartIndex = rowStartIndex,
                SortItems = sortItems
            };
        }

        #endregion
        #region NewFetchCriteria

        public static FetchCriteria<TField, TRelation> NewFetchCriteria<TField, TRelation>()
        {
            return new FetchCriteria<TField, TRelation>();
        }
        public static FetchCriteria<TField, TRelation> NewFetchCriteria<TField, TRelation>(string criteriaId, ParameterCollection parameters)
        {
            return new FetchCriteria<TField, TRelation>()
            {
                CriteriaId = criteriaId,
                Parameters = parameters,
            };
        }
        public static FetchCriteria<TField, TRelation> NewFetchCriteria<TField, TRelation>(Filter<TField> filterItems, SortItemCollection<TField> sortItems,
            System.Collections.Generic.IEnumerable<TRelation> includedEntities, int? rowStartIndex, int? rowCount)
        {
            return new FetchCriteria<TField, TRelation>()
            {
                Filter = filterItems,
                IncludedEntities = RelationManager.CreateRelations(includedEntities),
                RowCount = rowCount,
                RowStartIndex = rowStartIndex,
                SortItems = sortItems
            };
        }

        #endregion
        #region NewFetchListCriteria

        public static FetchListCriteria<TField, TRelation> NewFetchListCriteria<TField, TRelation>()
        {
            return new FetchListCriteria<TField, TRelation>();
        }
        public static FetchListCriteria<TField, TRelation> NewFetchListCriteria<TField, TRelation>(string criteriaId, ParameterCollection parameters)
        {
            return new FetchListCriteria<TField, TRelation>()
            {
                CriteriaId = criteriaId,
                Parameters = parameters,
            };
        }
        public static FetchListCriteria<TField, TRelation> NewFetchListCriteria<TField, TRelation>(Filter<TField> filterItems, SortItemCollection<TField> sortItems,
            System.Collections.Generic.IEnumerable<TRelation> includedEntities, int? rowStartIndex, int? rowCount)
        {
            return new FetchListCriteria<TField, TRelation>()
            {
                Filter = filterItems,
                IncludedEntities = RelationManager.CreateRelations(includedEntities),
                RowCount = rowCount,
                RowStartIndex = rowStartIndex,
                SortItems = sortItems
            };
        }

        #endregion
        #region NewFetchCountCriteria

        public static FetchCountCriteria<TField> NewFetchCountCriteria<TField>()
        {
            return new FetchCountCriteria<TField>();
        }
        public static FetchCountCriteria<TField> NewFetchCountCriteria<TField>(string criteriaId, ParameterCollection parameters)
        {
            return new FetchCountCriteria<TField>()
            {
                CriteriaId = criteriaId,
                Parameters = parameters,
            };
        }
        public static FetchCountCriteria<TField> NewFetchCountCriteria<TField>(Filter<TField> filterItems)
        {
            return new FetchCountCriteria<TField>()
            {
                Filter = filterItems,
            };
        }

        #endregion
        #region NewSaveSettings

        public static SaveSettings NewSaveSettings(string criteriaId)
        {
            return new SaveSettings()
            {
                CriteriaId = criteriaId
            };
        }
        public static SaveSettings NewSaveSettings(string criteriaId, ParameterCollection parameters)
        {
            return new SaveSettings()
            {
                CriteriaId = criteriaId,
                Parameters = parameters,
            };
        }
        public static SaveSettings NewSaveSettings(string criteriaId, ParameterCollection parameters, SaveMode mode)
        {
            return new SaveSettings()
            {
                CriteriaId = criteriaId,
                Parameters = parameters,
                Mode = mode,
            };
        }

        #endregion
    }
}